package balmysundaycandy.more.low.level.user;

import com.google.appengine.repackaged.com.google.io.protocol.ProtocolMessage;
import com.google.apphosting.api.ApiProxy;
import com.google.apphosting.api.UserServicePb.CreateLoginURLRequest;
import com.google.apphosting.api.UserServicePb.CreateLoginURLResponse;
import com.google.apphosting.api.UserServicePb.CreateLogoutURLRequest;
import com.google.apphosting.api.UserServicePb.CreateLogoutURLResponse;

/**
 * user operations.
 * 
 * @author marblejenka
 *
 * @param <Request>
 * @param <Response>
 */
public abstract class UserOperation<Request extends ProtocolMessage<?>, Response extends ProtocolMessage<?>> {
	private static final String packageName = "user";

	public abstract Response call(Request request);

	public static final class CreateLoginURLOperation extends UserOperation<CreateLoginURLRequest, CreateLoginURLResponse> {
		@Override
		public CreateLoginURLResponse call(CreateLoginURLRequest request) {
			CreateLoginURLResponse response = new CreateLoginURLResponse();
			response.mergeFrom(ApiProxy.makeSyncCall(packageName, "CreateLoginURL", request.toByteArray()));
			return response;
		}
	}

	public static final class CreateLogoutURLOperation extends UserOperation<CreateLogoutURLRequest, CreateLogoutURLResponse> {
		@Override
		public CreateLogoutURLResponse call(CreateLogoutURLRequest request) {
			CreateLogoutURLResponse response = new CreateLogoutURLResponse();
			response.mergeFrom(ApiProxy.makeSyncCall(packageName, "CreateLogoutURL", request.toByteArray()));
			return response;
		}
	}
}
